<template>
	<el-dialog title="IM用户密码重置" v-model="visible" :width="400" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" ref="dialogForm" label-width="100px" label-position="left">
			<el-form-item label="新密码" prop="password">
				<el-input v-model="form.password" placeholder="新密码" maxlength="48" clearable show-password></el-input>
			</el-form-item>
			<el-form-item label="密码确认" prop="password1">
				<el-input v-model="form.password1" placeholder="密码确认" maxlength="48" clearable show-password></el-input>
			</el-form-item>
		</el-form>
		<template #footer>
			<el-button @click="visible=false">取 消</el-button>
			<el-button type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
		</template>
	</el-dialog>
</template>

<script>

export default {
	components: {
	},
	emits: ['success', 'closed'],
	data() {
		return {
			form: {
				account: "",
				password: "",
				password1:""
			},
			rules: {
				password: [
					{ required: true, message: '请输入新的密码'}
				],
				password1: [
					{ required: true, message: '请再次输入新的密码'},
					{validator: (rule, value, callback) => {
							if (value !== this.form.password) {
								callback(new Error('两次输入密码不一致'));
							}else{
								callback();
							}
						}}
				],
			},
			visible: false,
			isSaveing: false,
		}
	},
	mounted() {

	},
	methods: {
		//显示
		open() {
			this.visible = true;
			return this;
		},
		//表单提交方法
		submit() {
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					var res = await this.$API.chat.user.updateUserPassword.post(this.form);
						this.isSaveing = false;
					if (res.code == 200) {
						this.visible = false;
						this.$message.success("操作成功")
					} else {
						this.$alert(res.message, "提示", {type: 'error'})
					}
				}
			})
		},
		//表单注入数据
		setData(data) {
			this.form.account = data.accountId
		}
	}
}
</script>

<style>
</style>
